package com.waitingresult;

import com.waitingresult.entity.Student;
import com.waitingresult.service.StudentService;

import java.util.ArrayList;

/**
 * @Author: WangShuai
 * @CreateTime: 2022-12-29  15:15
 * @Description:
 * @Version: 1.0
 */
public class ThreadSaveBatchService implements Runnable{

    private StudentService studentService;
    public ThreadSaveBatchService(StudentService studentService) {
        this.studentService = studentService;
    }

    @Override
    public void run() {
        ArrayList<Student> students = new ArrayList<>();
        for (int i = 0; i < 10000; i++) {
            int i1 = 10000000 + i;
            Student student = new Student();
            student.setName("TestName" + i);
            student.setPhone(i1 + "");
            students.add(student);
            if(students.size() > 1000){
                studentService.saveBatch(students);
                students.clear();
            }
        }
    }
}
